package com.example.dllo.my36kr.share.finish;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.dllo.my36kr.R;
import com.example.dllo.my36kr.share.all.AllWebActivity;
import com.example.dllo.my36kr.share.all.AllAdapter;
import com.example.dllo.my36kr.share.all.AllBean;
import com.example.dllo.my36kr.tools.BaseFragment;
import com.example.dllo.my36kr.tools.MyApp;
import com.example.dllo.my36kr.tools.NetTool;
import com.example.dllo.my36kr.tools.StaticUrl;

/**
 * Created by dllo on 16/8/17.
 */
public class FinishFragment extends BaseFragment {

    private ListView listView;
    private AllAdapter adapter;

    @Override
    protected int setLayout() {
        return R.layout.fragment_share_finish;
    }

    @Override
    protected void initView() {
        listView = bindView(R.id.lv_share_finish);
        adapter = new AllAdapter(MyApp.getContext());

    }

    @Override
    protected void initData() {
        mNetTool.getNetData(StaticUrl.SHARE_FINISH_URL, AllBean.class, new NetTool.NetListener<AllBean>() {
            @Override
            public void onSuccess(final AllBean allBean) {
                adapter.setAllBeen(allBean);
                listView.setAdapter(adapter);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        Intent intent = new Intent(getActivity(), AllWebActivity.class);
                        intent.putExtra("id",String.valueOf(allBean.getData().getData().get(position).getCrowdFundingId()));
                        startActivity(intent);
                    }
                });
            }

            @Override
            public void onError(String errorMsg) {

            }
        });

    }
}
